<?php
echo '<' . '?xml version="1.0" encoding="UTF-8"?' . '>' . "\r\n";
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
		xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
        xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">' . "\r\n";

$time = time() - 86400;
foreach($this->cache()->getCategories() AS $category) {
	$url = $this->url('category/index', array('name' => $category['name']))->assemble($category['lang']);
	$date = $this->date($time, 'Y-m-d')->assemble($category['lang']);
	echo "\t<url>\r\n";
	echo "\t\t<loc>{$url}</loc>\r\n";
	if($category['cover']) {
		$cover = $category['_cover']['thumb'];
		echo "\t\t<image:image>\r\n";
		echo "\t\t\t<image:loc>{$cover}</image:loc>\r\n";
		echo "\t\t</image:image>\r\n";
	}
	echo "\t\t<lastmod>{$date}</lastmod>\r\n";
	echo "\t\t<changefreq>daily</changefreq>\r\n";
	echo "\t</url>\r\n";
}
$url = $this->url('sns/index')->assemble($category['lang']);
$date = $this->date($time, 'Y-m-d')->assemble($category['lang']);
echo "\t<url>\r\n";
echo "\t\t<loc>{$url}</loc>\r\n";
echo "\t\t<lastmod>{$date}</lastmod>\r\n";
echo "\t\t<changefreq>daily</changefreq>\r\n";
echo "\t</url>\r\n";

foreach($this->cache()->index()->getRecommendSpecials(array('limit' => 50)) AS $special) {
	$url = $this->url('special/index', array('name' => $special['name']))->assemble($special['lang']);
	$date = $this->date($time, 'Y-m-d')->assemble($special['lang']);
	$cover = $special['_cover'];
	$_cover = isset($cover['thumb']) ? $cover['thumb'] : null;
	echo "\t<url>\r\n";
	echo "\t\t<loc>{$url}</loc>\r\n";
	if($_cover) {
		echo "\t\t<image:image>\r\n";
		echo "\t\t\t<image:loc>{$_cover}</image:loc>\r\n";
		echo "\t\t</image:image>\r\n";
	}
	echo "\t\t<lastmod>{$date}</lastmod>\r\n";
	echo "\t\t<changefreq>daily</changefreq>\r\n";
	echo "\t</url>\r\n";
}

echo '</urlset>';
?>
